home *** CD-ROM | disk | FTP | other *** search
- /* © 1988, Bowers Development Corp. */
- /* DialogAids.c */
-
- #include "DoScrap.h"
- #include "Scrolling.h"
- #include "WindowAids.h"
-
- #include "DialogAids.h"
-
-
- /*----------*/
- pascal void LineItem (dialog, itemNr)
- DialogPtr dialog;
- short itemNr;
- {
- short itemType;
- Handle item;
- Rect itemRect;
- PenState savePen;
-
- GetDItem (dialog, itemNr, &itemType, &item, &itemRect);
- GetPenState (&savePen);
- PenNormal ();
- PenPat (gray);
- MoveTo (itemRect.left, itemRect.top);
- LineTo (itemRect.right - 1, itemRect.bottom - 1);
- SetPenState (&savePen);
- } /*LineItem*/
-
- /*----------*/
- pascal void RectItem (dialog, itemNr)
- DialogPtr dialog;
- short itemNr;
- {
- short itemType;
- Handle item;
- Rect itemRect;
- PenState savePen;
-
- GetDItem (dialog, itemNr, &itemType, &item, &itemRect);
- GetPenState (&savePen);
- PenNormal ();
- FrameRect (&itemRect);
- SetPenState (&savePen);
- } /*RectItem*/
-
- /*----------*/
- void SetUserItem (itemNr, doDraw)
- short itemNr;
- ProcPtr doDraw;
- {
- short itemType;
- Handle item;
- Rect itemRect;
-
- GetDItem (thePort, itemNr, &itemType, &item, &itemRect);
- SetDItem (thePort, itemNr, itemType, (Handle) doDraw, &itemRect);
- } /*SetUserItem*/
-
- /*----------*/
- void OutlineButton (itemNr)
- short itemNr;
- {
- short itemType;
- Handle item;
- Rect itemRect;
- PenState savePen;
-
- GetDItem (thePort, itemNr, &itemType, &item, &itemRect);
- GetPenState (&savePen);
- PenNormal ();
- PenSize (3, 3);
- InsetRect (&itemRect, -4, -4);
- FrameRoundRect (&itemRect, 16, 16);
- SetPenState (&savePen);
- } /*OutlineButton*/
-
- /*----------*/
- void EnableDItem (itemNr, enable)
- short itemNr;
- Boolean enable;
- {
- short itemType;
- Handle item;
- Rect itemRect;
- ControlHandle control;
-
- GetDItem (thePort, itemNr, &itemType, &item, &itemRect);
- itemType = itemType & ~itemDisable;
- SetDItem (thePort, itemNr, itemType, item, &itemRect);
- control = (ControlHandle) item;
- HiliteScroll (control, enable);
- } /*EnableDItem*/
-
- /*----------*/
- void SetDText (itemNr, text)
- short itemNr;
- Str255 text;
- {
- short itemType;
- Handle item;
- Rect itemRect;
-
- GetDItem (thePort, itemNr, &itemType, &item, &itemRect);
- SetIText (item, text);
- } /*SetDText*/
-
- /*----------*/
- void GetDText (itemNr, text)
- short itemNr;
- Str255 text;
- {
- short itemType;
- Handle item;
- Rect itemRect;
-
- GetDItem (thePort, itemNr, &itemType, &item, &itemRect);
- GetIText (item, text);
- } /*GetDText*/
-
- /*----------*/
- void SetDNum (itemNr, num)
- short itemNr;
- long num;
- {
- Str255 text;
-
- NumToString (num, text);
- SetDText (itemNr, text);
- } /*SetDNum*/
-
- /*----------*/
- void GetDNum (itemNr, num)
- short itemNr;
- long *num;
- {
- Str255 text;
-
- GetDText (itemNr, text);
- StringToNum (text, num);
- } /*GetDNum*/
-
- /*----------*/
- void SetCheckbox (itemNr, checked)
- short itemNr;
- Boolean checked;
- {
- short itemType;
- Handle item;
- Rect itemRect;
- ControlHandle control;
-
- GetDItem (thePort, itemNr, &itemType, &item, &itemRect);
- control = (ControlHandle) item;
- SetCtlMax (control, 1);
- SetCtlValue (control, checked);
- } /*SetCheckbox*/
-
- /*----------*/
- void DoCheckbox (itemNr, checked)
- short itemNr;
- Boolean *checked;
- {
- *checked = !*checked;
- SetCheckbox (itemNr, *checked);
- } /*DoCheckbox*/
-
- /*----------*/
- void SetRadio (firstItem, choice)
- short firstItem;
- short choice;
- {
- SetCheckbox (firstItem + (choice - 1), true);
- } /*SetRadio*/
-
- /*----------*/
- void DoRadio (firstItem, itemNr, choice)
- short firstItem;
- short itemNr;
- short *choice;
- {
- SetCheckbox (firstItem + (*choice - 1), false);
- *choice = itemNr - firstItem + 1;
- SetCheckbox (firstItem + (*choice - 1), true);
- } /*DoRadio*/
-
- /*----------*/
- void InvertIcon (short iconNr);
- void InvertIcon (iconNr)
- short iconNr;
- {
- short itemType;
- Handle item;
- Rect itemRect;
-
- GetDItem (thePort, iconNr, &itemType, &item, &itemRect);
- InsetRect (&itemRect, 1, 1);
- InvertRect (&itemRect);
- } /*InvertIcon*/
-
- /*----------*/
- void DoIconRadio (firstIcon, itemNr, choice)
- short firstIcon;
- short itemNr;
- short *choice;
- {
- InvertIcon (firstIcon + (*choice - 1));
- *choice = (itemNr - firstIcon) + 1;
- InvertIcon (firstIcon + (*choice - 1));
- } /*DoIconRadio*/
-
- /*----------*/
- void SetControl (itemNr, choice)
- short itemNr;
- short choice;
- {
- short itemType;
- Handle item;
- Rect itemRect;
- ControlHandle control;
-
- GetDItem (thePort, itemNr, &itemType, &item, &itemRect);
- control = (ControlHandle) item;
- SetCtlValue (control, choice);
- } /*SetControl*/
-
- /*----------*/
- short GetControl (itemNr)
- short itemNr;
- {
- short itemType;
- Handle item;
- Rect itemRect;
- ControlHandle control;
-
- GetDItem (thePort, itemNr, &itemType, &item, &itemRect);
- control = (ControlHandle) item;
- return (GetCtlValue (control));
- } /*GetControl*/
-
- /*----------*/
- void DoPalette (itemNr, choice)
- short itemNr;
- short *choice;
- {
- *choice = GetControl (itemNr);
- } /*DoPalette*/
-
- /*----------*/
- void DoMultiState (itemNr, value)
- short itemNr;
- short *value;
- {
- short itemType;
- Handle item;
- Rect itemRect;
- ControlHandle control;
-
- GetDItem (thePort, itemNr, &itemType, &item, &itemRect);
- control = (ControlHandle) item;
- if (*value == GetCtlMax (control)) {
- *value = GetCtlMin (control);
- } else {
- *value += 1;
- }
- SetCtlValue (control, *value);
- } /*DoMultiState*/
-
- /*----------*/
- void SetScrollItem (itemNr, value, min, max, pageSize)
- short itemNr;
- short value;
- short min;
- short max;
- short pageSize;
- {
- short itemType;
- Handle item;
- Rect itemRect;
- ControlHandle scroll;
-
- GetDItem (thePort, itemNr, &itemType, &item, &itemRect);
- scroll = (ControlHandle) item;
- SetCtlMin (scroll, min);
- SetCtlMax (scroll, max);
- SetCtlValue (scroll, value);
- SetCRefCon (scroll, pageSize);
- HiliteScroll (scroll, (min < max));
- } /*SetScrollItem*/
-
- /*----------*/
- void DoScrollItem (itemNr, value)
- short itemNr;
- short *value;
- {
- short itemType;
- Handle item;
- Rect itemRect;
- ControlHandle scroll;
-
- GetDItem (thePort, itemNr, &itemType, &item, &itemRect);
- scroll = (ControlHandle) item;
- *value = GetCtlValue (scroll);
- } /*DoScrollItem*/
-
- /*----------*/
- void DrawPopup (itemNr, menuID, choice)
- short itemNr;
- short menuID;
- short choice;
- {
- short itemType;
- Handle item;
- Rect itemRect;
-
- GetDItem (thePort, itemNr, &itemType, &item, &itemRect);
- UpdatePopup (itemRect, menuID, choice);
- } /*DrawPopup*/
-
- /*----------*/
- void DoPopup (itemNr, menuID, choice)
- short itemNr;
- short menuID;
- short *choice;
- {
- short itemType;
- Handle item;
- Rect itemRect;
-
- GetDItem (thePort, itemNr, &itemType, &item, &itemRect);
- TrackPopup (itemRect, menuID, choice);
- } /*DoPopup*/
-
- /*----------*/
- void InvertLabel (itemNr)
- short itemNr;
- {
- short itemType;
- Handle item;
- Rect itemRect;
-
- GetDItem (thePort, itemNr, &itemType, &item, &itemRect);
- InvertRect (&itemRect);
- } /*InvertLabel*/
-
- /*----------*/
- ListHandle Vert1List (itemNr)
- short itemNr;
- {
- short itemType;
- Handle item;
- Rect itemRect;
- Rect dataBounds;
- Point cSize;
- ListHandle list;
-
- GetDItem (thePort, itemNr, &itemType, &item, &itemRect);
- itemRect.right = itemRect.right - 15; /*for scroll bar*/
- SetRect (&dataBounds, 0, 0, 1, 0); /*one column, no rows*/
- SetPt (&cSize, itemRect.right - itemRect.left, 0);
- list = LNew (&itemRect, /*dialog item's rect*/
- &dataBounds, /*one column, no rows*/
- cSize, /*cell size: full width, standard height*/
- 0, /*procid - standard text list*/
- thePort, /*parent window*/
- false, /*don't draw*/
- false, /*has grow*/
- false, /*no horizontal scroll*/
- true); /*vertical scroll*/
- return (list);
- } /*Vert1List*/
-
- /*----------*/
- void AddToList (data, list)
- char data [];
- ListHandle list;
- {
- short newRow;
- Point newCell;
- unsigned char dataLen;
-
- #define maxint 32767
-
- newRow = LAddRow (1, maxint, list);
- SetPt (&newCell, 0, newRow);
- dataLen = data [0];
- LSetCell (&(data [1]), dataLen, newCell, list);
- } /*AddToList*/
-
- /*----------*/
- void DrawList (list)
- ListHandle list;
- {
- PenState savePen;
- Rect frame;
-
- GetPenState (&savePen);
- PenNormal ();
- frame = (**list).rView;
- InsetRect (&frame, -1, -1);
- FrameRect (&frame);
- SetPenState (&savePen);
- LUpdate ((**list).port->visRgn, list);
- } /*DrawList*/
-
- /*----------*/
- Boolean FilterList (event, list, listItem, dblClickItem, itemHit)
- EventRecord *event;
- ListHandle list;
- short listItem;
- short dblClickItem;
- short *itemHit;
- {
- Boolean filtered;
- Point mousePos;
-
- filtered = false;
- if ((*event).what == mouseDown) {
- mousePos = (*event).where;
- GlobalToLocal (&mousePos);
- if (FindDItem (thePort, mousePos) + 1 == listItem) {
- if (LClick (mousePos, (*event).modifiers, list)) {
- *itemHit = dblClickItem;
- } else {
- *itemHit = listItem;
- }
- filtered = true;
- }
- }
- return (filtered);
- } /*FilterList*/
-
- /*----------*/
- Boolean FilterScroll (event, scrollItem, actionProc, itemHit)
- EventRecord *event;
- short scrollItem;
- ProcPtr actionProc;
- short *itemHit;
- {
- Boolean filtered;
- Point mousePos;
- short partCode;
- ControlHandle whichControl;
-
- filtered = false;
- if ((*event).what == mouseDown) {
- mousePos = (*event).where;
- GlobalToLocal (&mousePos);
- if (FindDItem (thePort, mousePos) + 1 == scrollItem) {
- partCode = FindControl (mousePos, thePort, &whichControl);
- if (partCode != 0) {
- TrackScroll (whichControl, partCode, mousePos, actionProc);
- *itemHit = scrollItem;
- filtered = true;
- }
- }
- }
- return (filtered);
- } /*FilterScroll*/
-
- /*----------*/
- void FilterIcon (event, firstIcon, choice)
- EventRecord *event;
- short firstIcon;
- short choice;
- {
- short itemType;
- Handle item;
- Rect itemRect;
-
- if (((*event).what == updateEvt)
- && ((WindowPtr) (*event).message == thePort)) {
- GetDItem (thePort, firstIcon + (choice - 1), &itemType, &item, &itemRect);
- PlotIcon (&itemRect, item);
- ValidRect (&itemRect);
- InsetRect (&itemRect, 1, 1);
- InvertRect (&itemRect);
- }
- } /*FilterIcon*/
-
- /*----------*/
- pascal Boolean StandardFilter (whichDialog, event, itemHit)
- DialogPtr whichDialog;
- EventRecord *event;
- short *itemHit;
- {
- #define returnKey 13
- #define enter 3
- #define esc 27
- #define pushButton (ctrlItem + btnCtrl)
-
- Boolean filtered;
- DialogPeek whichPeek;
- short defItem;
- char key;
- short itemType;
- Handle item;
- Rect itemRect;
- long finalTicks;
-
- filtered = false;
- whichPeek = (DialogPeek) whichDialog;
- defItem = whichPeek->aDefItem;
- switch ((*event).what) {
- case keyDown:
- case autoKey:
- key = (*event).message & charCodeMask;
- if ((key == returnKey) || (key == enter) || (key == esc)) {
- if ((key == returnKey) || (key == enter)) {
- *itemHit = defItem;
- } else if (key == esc) {
- *itemHit = Cancel;
- }
- GetDItem (whichDialog, *itemHit, &itemType, &item, &itemRect);
- if ((itemType & itemDisable) == 0) {
- if ((itemType & (255 - itemDisable)) == pushButton) {
- HiliteControl ((ControlHandle) item, inButton);
- Delay (8, &finalTicks);
- HiliteControl ((ControlHandle) item, 0);
- }
- filtered = true;
- } /*if*/
- } else {
- if ((((*event).modifiers & cmdKey) != 0)
- && ((key == 'x') || (key == 'c') || (key == 'v'))) {
- *itemHit = (whichPeek)->editField + 1;
- switch (key) {
- case 'x':
- DlgCut (whichDialog);
- scrapDirty = (*itemHit > 0);
- break;
- case 'c':
- DlgCopy (whichDialog);
- scrapDirty = (*itemHit > 0);
- *itemHit = 0;
- break;
- case 'v':
- DlgPaste (whichDialog);
- break;
- } /*switch*/
- if (*itemHit > 0) {
- GetDItem (whichDialog, *itemHit, &itemType, &item, &itemRect);
- if ((itemType & itemDisable) == 0) {
- filtered = true;
- }
- }
- if (!filtered) {
- (*event).what = nullEvent;
- }
- }
- }
- break;
- case updateEvt:
- if ((WindowPtr) (*event).message == thePort) {
- GetDItem (whichDialog, defItem, &itemType, &item, &itemRect);
- if ((itemType & (255 - itemDisable)) == pushButton) {
- OutlineButton (defItem);
- }
- }
- break;
- } /*switch*/
- return (filtered);
- } /*StandardFilter*/
-